﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Evolution.Structure;
using GameProject.ViewModel;
using Evolution.Structure.Globe.Units;
using Evolution.Structure.Globe;
using Evolution.Structure.Globe.Details;

namespace GameProject
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    /// 
    
    public partial class MainWindow : Window
    {
        public static Player MyPlayer { get; set; }
        public Game MyGame { get; set; }

        public MainWindow()
        {
            //System.Threading.Thread.Sleep(2000);
            InitializeComponent();
            this.DataContext = new MainWindowViewModel();
            sound.Play();          
        }

        private void createTestData()
        {
            try
            {
                Nation testNation = new Nation();
                testNation.Name = "America";

                testNation.StartingUnits.Add(new Unit() { Name = "Archer", BuildingCosts= 200, MoveableInAir=true, MoveableOnLand=true, MoveableOnSea=true, Health=10, MaintenanceCosts=10, MovePoints=3 });
                testNation.StartingUnits.Add(new Unit() { Name = "Axeman", BuildingCosts = 100, MoveableInAir = false, MoveableOnLand = true, MoveableOnSea = false, Health = 8, MaintenanceCosts = 2, MovePoints = 6 });
                testNation.StartingTechnologies.Add(new Technology() { Name = "Agriculture", ResearchCosts = 60 });
                testNation.StartingTechnologies.Add(new Technology() { Name = "Archery", ResearchCosts = 60 });
                testNation.StartingTechnologies.Add(new Technology() { Name = "Astronomy", ResearchCosts = 2000 });

                testNation.StartingTechnologies[0].Predecessors.Add(testNation.StartingTechnologies[1]);
                testNation.StartingTechnologies[0].Predecessors.Add(testNation.StartingTechnologies[2]);

                testNation.StartingTechnologies[1].Predecessors.Add(testNation.StartingTechnologies[0]);
                
                testNation.StartingTechnologies[2].Predecessors.Add(testNation.StartingTechnologies[0]);
                testNation.StartingTechnologies[2].Predecessors.Add(testNation.StartingTechnologies[1]);


                testNation.SeedMoney = 2222;
                testNation.CityNames = new List<String> { "New York", "Boston" };
                testNation.Benefits.Add(new Evolution.Benefit() { Name = "testBenefit1" });
                testNation.Benefits.Add(new Evolution.Benefit() { Name = "testBenefit2" });

                
                GlobalVar.Encyclopdia.NationList.Add(testNation);
                GlobalVar.Encyclopdia.TechnologyList = testNation.StartingTechnologies;
                GlobalVar.Encyclopdia.UnitList = testNation.StartingUnits;
                GlobalVar.Encyclopdia.BuildingList.Add(new Building() { Name = "Airport", BuildingCosts = 200 });
                GlobalVar.Encyclopdia.BuildingList.Add(new Building() { Name = "Barracks", BuildingCosts = 3000 });

                GlobalVar.Encyclopdia.BuildingList[0].RequiredTechnologies.Add(testNation.StartingTechnologies[0]);
                GlobalVar.Encyclopdia.BuildingList[1].RequiredTechnologies.Add(testNation.StartingTechnologies[1]);
                GlobalVar.Encyclopdia.BuildingList[1].RequiredTechnologies.Add(testNation.StartingTechnologies[2]);

                GlobalVar.Encyclopdia.BuildingList[0].Benefits = testNation.Benefits;

                GlobalVar.Encyclopdia.UnitList[0].Requiredtechnologies.Add(GlobalVar.Encyclopdia.TechnologyList[0]);
                GlobalVar.Encyclopdia.UnitList[1].Requiredtechnologies.Add(GlobalVar.Encyclopdia.TechnologyList[1]);
                GlobalVar.Encyclopdia.UnitList[1].Requiredtechnologies.Add(GlobalVar.Encyclopdia.TechnologyList[2]);

                GlobalVar.Encyclopdia.UnitList[0].RequiredBuildings.Add(GlobalVar.Encyclopdia.BuildingList[0]);
                GlobalVar.Encyclopdia.UnitList[1].RequiredBuildings.Add(GlobalVar.Encyclopdia.BuildingList[0]);
                GlobalVar.Encyclopdia.UnitList[1].RequiredBuildings.Add(GlobalVar.Encyclopdia.BuildingList[1]);


                Nation testNation2 = new Nation();
                testNation2.Name = "China";
                GlobalVar.Encyclopdia.NationList.Add(testNation2);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }

        private int playing = 1;

        private void soundIcon_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            if (playing == 1)
            {
                sound.Pause();
                playing = 0;
            }
            else
            {
                sound.Play();
                playing = 1;
            }
        }
   }
}
